export function tabsIsAdd(val, breadcrumbDataList) {
    // val数据模板 breadcrumb为面包屑
    // {
    //     router: 'dsadad',
    //     title: '主页2',
    //     activate: true
    // }
    // breadcrumbDataList 顶部菜单的数据
    let tabsExist = false
    for (let index = 0; index < breadcrumbDataList.data.length; index++) {
        const element = breadcrumbDataList.data[index];
        if (element.router == val.router) {
            element.activate = true
            tabsExist = true
        } else {
            element.activate = false
        }

    }
    if (tabsExist == false) {

        breadcrumbDataList.data.splice(breadcrumbDataList.data.length
            , 0, {
            router: val.router,
            title: val.title,
            activate: true
        }
        )
    }

    return
}

export function tabsIsDelete(val, breadcrumbDataList) {
    // val数据模板  breadcrumb为面包屑
    // {
    //     router: 'dsadad',
    //     title: '主页2',
    //     activate: true
    // }
    // breadcrumbDataList 顶部菜单的数据

    // ==================
    // 代码示例
    // const val = {
    //     router: '/price/add',
    //     title: '发布报价',
    // }
    // breadcrumb.data = [
    //     {
    //         title: "发布报价",
    //         router: '/price/add-',
    //     }]
    // route.push({ path: val.router })
    // tabsIsAdd(val, breadcrumbDataList)
    // =================

    for (let index = 0; index < breadcrumbDataList.data.length; index++) {
        const element = breadcrumbDataList.data[index];
        // 存储激活状态，如果是为激活的顶部菜单则需要需要进行激活切换处理

        if (element.router == val.router) {
            const activate = element.activate
            breadcrumbDataList.data.splice(index
                , 1
            )
            if (activate == true) {
                if (index < breadcrumbDataList.data.length) {
                    breadcrumbDataList.data[index].activate = true
                    return breadcrumbDataList.data[index]
                } else {
                    breadcrumbDataList.data[index - 1].activate = true
                    return breadcrumbDataList.data[index - 1]
                }
            } else {
                if (index < breadcrumbDataList.data.length) {

                    return breadcrumbDataList.data[index]
                } else {

                    return breadcrumbDataList.data[index - 1]
                }
            }


        }
    }
    return
}